package com.ruoyi.cost.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.cost.domain.MedicalCostRegister;
import com.ruoyi.cost.service.IMedicalCostRegisterService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 挂号费用Controller
 * 
 * @author Atong
 * @date 2022-01-03
 */
@RestController
@RequestMapping("/cost/register")
public class MedicalCostRegisterController extends BaseController
{
    @Autowired
    private IMedicalCostRegisterService medicalCostRegisterService;

    /**
     * 查询挂号费用列表
     */
    @PreAuthorize("@ss.hasPermi('cost:register:list')")
    @GetMapping("/list")
    public TableDataInfo list(MedicalCostRegister medicalCostRegister)
    {
        startPage();
        List<MedicalCostRegister> list = medicalCostRegisterService.selectMedicalCostRegisterList(medicalCostRegister);
        //将等待中自动改为
       /* boolean f=true;
        for (int i=0;i<list.size();i++) {
            if(list.get(i).getType()==1){
                f=false;
            }
            if(f){
                if( list.get(i).getType()!=3){
                    list.get(i).setType(1l);
                    f=true;
                    medicalCostRegisterService.updateMedicalCostRegister(list.get(i));
                    break;
                }
            }
        };*/

        return getDataTable(list);
    }

    /**
     * 导出挂号费用列表
     */
    @PreAuthorize("@ss.hasPermi('cost:register:export')")
    @Log(title = "挂号费用", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MedicalCostRegister medicalCostRegister)
    {
        List<MedicalCostRegister> list = medicalCostRegisterService.selectMedicalCostRegisterList(medicalCostRegister);
        ExcelUtil<MedicalCostRegister> util = new ExcelUtil<MedicalCostRegister>(MedicalCostRegister.class);
        util.exportExcel(response, list, "挂号费用数据");
    }

    /**
     * 获取挂号费用详细信息
     */
    @PreAuthorize("@ss.hasPermi('cost:register:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(medicalCostRegisterService.selectMedicalCostRegisterById(id));
    }

    /**
     * 新增挂号费用
     */
    @PreAuthorize("@ss.hasPermi('cost:register:add')")
    @Log(title = "挂号费用", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MedicalCostRegister medicalCostRegister)
    {
        return toAjax(medicalCostRegisterService.insertMedicalCostRegister(medicalCostRegister));
    }

    /**
     * 修改挂号费用
     */
    @PreAuthorize("@ss.hasPermi('cost:register:edit')")
    @Log(title = "挂号费用", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MedicalCostRegister medicalCostRegister)
    {

        return toAjax(medicalCostRegisterService.updateMedicalCostRegister(medicalCostRegister));
    }

    /**
     * 删除挂号费用
     */
    @PreAuthorize("@ss.hasPermi('cost:register:remove')")
    @Log(title = "挂号费用", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(medicalCostRegisterService.deleteMedicalCostRegisterByIds(ids));
    }
}
